package com.flower.sequence.parse;

import com.eaio.uuid.UUIDGen;
import com.flower.sequence.service.string.EaioStringSequenceGenerator;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.w3c.dom.Element;

import java.util.UUID;

/**
 * @author shanks on 2019-10-11
 */
public class EaioUUIDBeanDefinitionParse extends AbstractSingleBeanDefinitionParser {

    @Override
    protected Class<?> getBeanClass(Element element) {
        return EaioStringSequenceGenerator.class;
    }

    @Override
    protected void doParse(Element element, BeanDefinitionBuilder builder) {
        builder.addPropertyValue("value", new UUID(UUIDGen.newTime(), UUIDGen.getClockSeqAndNode()).toString());
    }
}
